package com.beaut.project.control;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beaut.project.service.WorkFlowService;
import com.beaut.project.service.XMAssistService;
import com.beaut.project.service.XMFinanceService;
import com.beaut.project.service.XMService;
import com.beaut.project.util.FlowUtility;
import com.beaut.project.util.Utility;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import yh.core.funcs.person.data.YHPerson;
import yh.core.global.YHConst;
/**
 * 工作流模块
 * @author ljs
 *
 */
@Controller
@RequestMapping("/workFlow")
public class WorkFlowController extends BaseControl{
	@Autowired 
	WorkFlowService workFlowService;
	@Autowired 
	XMService xmService;
	@Autowired 
	XMAssistService xmAssistService;
	@Autowired 
	XMFinanceService xmFinanceService;
	private WebClient wc = null;
	
	@PostConstruct
	public void  init(){  
		wc = new WebClient();
    }  
	
    @RequestMapping(value = "/toShenpi", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String toShenpi(HttpServletRequest request) {
    	 String pageXml="";
		try {
		        wc.getOptions().setJavaScriptEnabled(true); //启用JS解释器，默认为true  
		        wc.getOptions().setCssEnabled(false); //禁用css支持  
		        wc.getOptions().setThrowExceptionOnScriptError(false); //js运行错误时，是否抛出异常  
		        wc.getOptions().setTimeout(10000); //设置连接超时时间 ，这里是10S。如果为0，则无限期等待  
		        String sn=request.getServerName();
		        int port=request.getServerPort();
		        String cp=request.getContextPath();
		        String businessModule=request.getParameter("moduleFlow");
		        String businessId=request.getParameter("businessId");
		        if(businessModule==null || businessId==null)
		        	return Utility.rtJson(Utility.RETURN_ERROR, "提交数据不正确，缺少参数", null);
		        int flowId=FlowUtility.getFlowIdByName(businessModule);
		        HttpSession session = request.getSession(true);
		    	YHPerson person=(YHPerson)session.getAttribute(YHConst.LOGIN_USER);
		    	
			    int runId=this.isCreateNew(businessModule, businessId);
			  
			    if(runId==0){
		        HtmlPage page = wc.getPage("http://"+sn+":"+port+cp+"/yh/core/funcs/workflow/act/YHBusinessToFlowAct/getFlowUrl.act?" +
		        		"flowId="+flowId+"&SEQ_ID="+person.getSeqId()+"&USER_NAME="+person.getUserName()+"&DEPT_ID="+person.getDeptId()+"&USER_PRIV="+person.getUserPriv()+"&USER_ID="+person.getUserId()
		        		+"&flowBusinessUrl="+URLEncoder.encode(request.getParameter("flowBusinessUrl"),"UTF-8"));  
		         pageXml = page.getBody().asText(); //以xml的形式获取响应文本  
		        
		         JsonParser jsonparer = new JsonParser();
		         JsonObject jo = jsonparer.parse(pageXml).getAsJsonObject().getAsJsonObject();
		          runId=jo.get("rtData").getAsJsonObject().get("runId").getAsInt();
		         //插入数据
		          Map<String,Object> map=new HashMap();
		          String flow_link="/core/funcs/workflow/flowrun/list/print/index.jsp?runId="+runId+"&flowId="+flowId;
		      	  map.put("business_id", businessId);
		      	  map.put("business_module", businessModule);
		    	  map.put("flow_run_id", runId);
		    	  map.put("business_view", request.getParameter("flowBusinessUrl"));
		      	  map.put("flow_link", flow_link);
		    	  map.put("business_status", 1);
		          workFlowService.addBusinessFlow(map);
		         
			    }
			    else{
			     //跳转数据
			    	Map<String,Object> map=new HashMap();
			    	map.put("runId", runId);
			    	Map m=workFlowService.getFlowRunPrcs(map);
			    	String prcs_id=m.get("prcs_id").toString();
			    	String flow_prcs=m.get("flow_prcs").toString();
			       String url="http://"+sn+":"+port+cp+"/core/funcs/workflow/flowrun/list/inputform/index.jsp?runId="+runId+"&flowId="+flowId+"&prcsId="+prcs_id+"&flowPrcs="+flow_prcs+"&sortId=&skin=";
			       String result = "{\"url\":\"" + url + "\",\"runId\":\""+runId+"\"}";
					
			        pageXml="{\"rtState\":\"0\", \"rtMsrg\":\"成功提交\", \"rtData\":"+result+"}";
			    }
		      
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Utility.rtJson(Utility.RETURN_ERROR, "提交审批失败", null);
		}	
    	
		return pageXml;
//    	return workFlowService.addGDMain(requestParameterToMap(request));
    }
    /**
     *判断业务是否是需要重新创建流程 
     */
    private int isCreateNew(String businessModule,String businessId){
    	Map<String,Object> map=new HashMap();
    	map.put("business_id", businessId);
    	map.put("business_module", businessModule);
    	int runId=workFlowService.getBusinessFlow(map);
    	
    	return runId;
    }
    /**
     *判断业务是否是需要重新创建流程 
     */
    private int addBusinessFlow(String businessModule,String businessId){
    	Map<String,Object> map=new HashMap();
    	map.put("business_id", businessId);
    	map.put("business_module", businessModule);
    	int runId=workFlowService.getBusinessFlow(map);
    	
    	return runId;
    }

    @RequestMapping(value = "/toViewBusiness", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String toViewBusiness(HttpServletRequest request) {

    	return workFlowService.toViewBusiness(requestParameterToMap(request));
    }
    
    @RequestMapping(value = "/getFlowView", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getFlowView(HttpServletRequest request) {

    	return workFlowService.getFlowView(requestParameterToMap(request));
    }
    /**
     * 库存盘点审批,审批通过更新库存日志与数量
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDUpdateInventory", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDUpdateInventory(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDUpdateInventory(requestParameterToMap(request));
    }
    /**
     * 项目经济考评审核
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDUpdateEvaluation", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDUpdateEvaluation(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDUpdateEvaluation(requestParameterToMap(request));
    }
    
    /**
     * 工单领料退料审批
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDReturn", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDReturn(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDReturn(requestParameterToMap(request));
    }
    /**
     * 工单班组还款审核
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDAdvances", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDAdvances(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDAdvances(requestParameterToMap(request));
    }
    /**
     * 项目合同审核
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDUpdateContract", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDUpdateContract(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDUpdateContract(requestParameterToMap(request));
    }
    /**
     * 项目是否无合同审核
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDUpdateNoContract", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDUpdateNoContract(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDUpdateNoContract(requestParameterToMap(request));
    }
    /**
     * 工单内容审批的回调函数，用于更新工单base的状态
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDUpdateGDBaseStatus", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDUpdateGDBaseStatus(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDUpdateGDBaseStatus(requestParameterToMap(request));
    }
    /**
     * 现场利旧回调函数，更新预算材料的使用量
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDReuse", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDReuse(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDReuse(requestParameterToMap(request));
    }
    /**
     * 项目报账审核通过之后更新项目借款报账金额
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToUpdateXMBz", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToUpdateXMBz(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToUpdateXMBz(requestParameterToMap(request));
    }
    /**
     * 项目验收审批
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDUpdateXmCheckStatus", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDUpdateXmCheckStatus(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDUpdateXmCheckStatus(requestParameterToMap(request));
    }
    /**
     * 工单采购退料审批
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDReturnApply", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDReturnApply(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
		Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
		map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDReturnApply(map);
    }
    /**
     * 产品入库审批的回调函数，用于更新产品status的状态
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDUpdateGDProductStatus", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDUpdateGDProductStatus(HttpServletRequest request,HttpServletResponse response) {
    	return workFlowService.backToGDUpdateGDProductStatus(requestParameterToMap(request));
    }
    /**
     * 工单乙供领料审批的回调函数，同意就从工余库中自动出料，优先出本部门
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDSelfRequest", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDSelfRequest(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
		Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
		map.put("person_id", sessionMap.get("id"));
		map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDSelfRequest(map);
    }
    
    /**
     * 工单拆旧回收的回调函数，同意就入该部门的工余库
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDRecoveryMaterial", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDRecoveryMaterial(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
		Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
		map.put("person_id", sessionMap.get("id"));
		map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDRecoveryMaterial(map);
    }
    /**
     * 工单甲供借客户库的回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDBorrowCustomer", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDBorrowCustomer(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDBorrowCustomer(map);
    }
    /**
     * 工单甲供还客户库的回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDReturnCustomer", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDReturnCustomer(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDReturnCustomer(map);
    }
    
    /**
     * 工单甲供借工余库的回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDBorrowSelf", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDBorrowSelf(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDBorrowSelf(map);
    }
    /**
     * 工单甲供还工余库的回调函数,优先还其他部门（钱或者料）
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDReturnSelf", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDReturnSelf(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDReturnSelf(map);
    }
    /**
     * 工单采购申请的回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDPurchaseApply", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDPurchaseApply(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	return workFlowService.backToGDPurchaseApply(map);
    }
    /**
     * 订货入库的回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToProductIn", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToProductIn(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToProductIn(map);
    }
    /**
     * 甲供项目库领料
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDJgRequest", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDJgRequest(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDJgRequest(map);
    }

    
    /**
     * 项目进度支付回调处理
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMPayDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMPayDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.flowBackToXMPayDeal(map);
    }
    /**
     * 项目结算付款回调处理-施工
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMEndWorkerPayDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMEndWorkerPayDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.flowBackToXMEndWorkerPayDeal(map);
    }
    
    /**
     * 项目结算付款回调处理-采购
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMEndSupplyPayDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMEndSupplyPayDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.flowBackToXMEndSupplyPayDeal(map);
    }
    
    
    /**
     * 项目进度施工款支付回调处理
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMPayWorkerDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMPayWorkerDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.flowBackToXMPayWorkerDeal(map);
    }
    
    /**
     * 采购领料回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDPurchaseApplyUse", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDPurchaseApplyUse(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDPurchaseApplyUse(map);
    }
    /**
     * 领用厂家库，回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDSupplierApply", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDSupplierApply(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDSupplierApply(map);
    }

    /**
     * 项目材料平衡，回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMMaterBalanceDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String flowBackToXMMaterBalanceDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	return workFlowService.flowBackToXMMaterBalanceDeal(map);
    }
    

    /**
     * 成本固化，回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDBalance", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDBalance(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDBalance(map);
    }
    

    /**
     * 项目收入结算，回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMInmoneyBalanceDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMInmoneyBalanceDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.flowBackToXMInmoneyBalanceDeal(map);
    }

 
    /**
     * 项目收入结算，回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMPayBalanceDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMPayBalanceDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.flowBackToXMPayBalanceDeal(map);
    }

    
    /**
     * 项目回收质保金，回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMWarrantyDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMWarrantyDeal(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.flowBackToXMWarrantyDeal(map);
    }
    /**
     * 工单预算调整回调函数
     * @param request
     * @return
     */
    @RequestMapping(value = "/backToGDChangeAssume", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backToGDChangeAssume(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMap(request);
    	Map<String, Object> sessionMap = (Map<String, Object>) request.getSession().getAttribute("LOGIN_USER");
    	map.put("person_id", sessionMap.get("id"));
    	map.put("person", sessionMap.get("truename"));
    	return workFlowService.backToGDChangeAssume(map);
    }
    
    /**
     * 
     * 项目审批回调
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMBaseStatus", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMBaseStatus(HttpServletRequest request,HttpServletResponse response) {
    	Map<String,Object> m=requestParameterToMapUser(request);
    		m.put("xm_id", m.get("key"));
    	 xmService.flowBackToXMBaseStatus(m);
    	 xmAssistService.updateStartTimeAndGDSetByXM(m);
    	 return "1";
    }
    /**
     * 
     * 项目甲供入库审批回调
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMFlowInWarehouseStatus", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMFlowInWarehouseStatus(HttpServletRequest request,HttpServletResponse response) {
    	 Map<String, Object> map = requestParameterToMapUser(request);
    	return xmService.flowBackToXMFlowInWarehouseStatus(map);
    }
    @RequestMapping(value = "/backFlowToXMFlowOutWarehouseStatus", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMFlowOutWarehouseStatus(HttpServletRequest request,HttpServletResponse response) {
    	Map<String, Object> map = requestParameterToMapUser(request);
    	return xmService.backFlowToXMFlowOutWarehouseStatus(map);
    }
    /**
     * 
     * 项目进度开票审批回调
     * @param request
     * @return
     */
    @RequestMapping(value = "/backFlowToXMBasesDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMBasesDeal(HttpServletRequest request,HttpServletResponse response) {
    	 Map<String, Object> map = requestParameterToMapUser(request);
    	 map.put("id",map.get("key"));
    	return xmFinanceService.flowBackToXMBasesDeal(map);
    }
    /**
     * 
     * 项目进度收款审批回调
     * @param request
     * @return
     */ 
    @RequestMapping(value = "/backFlowToXMInMoneyDeal", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String backFlowToXMInMoneyDeal(HttpServletRequest request,HttpServletResponse response) {
    	 Map<String, Object> map = requestParameterToMapUser(request);
    	 map.put("id",map.get("key"));
    	return xmFinanceService.flowBackToXMInMoneyDeal(map);
    }
    /**
     * 
     * 员工借款报账审批
     * @param request
     * @return
     */ 
    @RequestMapping(value = "/employReimbursem", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String employReimbursem(HttpServletRequest request,HttpServletResponse response) {
    	 Map<String, Object> map = requestParameterToMapUser(request);
    	 map.put("id",map.get("key"));
    	return xmFinanceService.employReimbursem(map);
    }
    
}
